#======================================================================================================
# Date:     December 2023
# Article:  Vote Choices and Valence: Intercepts and Alternate Specifications, Political Analysis
# Authors:  Ingrid Mauerer, Gerhard Tutz
#======================================================================================================

#-----------------------------------------------------------------------------------
# This file contains the commands to run the models and create the tables 
# R version 4.2.2 
# Platform: x86_64-w64-mingw32/x64 (64-bit)
#-----------------------------------------------------------------------------------

#==================
# Packages
#==================
library("mlogit")

#---------------
# Load Data
#---------------
load("Data.RDS")

#===============================================================================
# Table 2: Gender based on (0-1) Coding with differing Reference Populations
#===============================================================================

### Model estimations

# Reference: male (1 female, 0 male)
m01GER <- mlogit(chosen ~ 0  | gender | 0, data=ElectionGER1998, shape="long", alt.var="party", reflevel = "CDU")
summary(m01GER)

# Reference: female (1 male, 0 female)
m02GER <- mlogit(chosen ~ 0 | gender2 | 0, data=ElectionGER1998, shape="long", alt.var="party", reflevel = "CDU")
summary(m02GER)

# extract s.e.:
se.m01GER <- round(sqrt(diag(solve(-m01GER$hessian))), digits=2)
se.m02GER <- round(sqrt(diag(solve(-m02GER$hessian))), digits=2)

### Build table
Table2 <- matrix(NA, 10, ncol = 6)
colnames(Table2) <- c("beta", "s.e.","e(beta)", "beta", "s.e.", "e(beta)")
rownames(Table2) <- c("Intercept CDU beta_10", "Intercept SPD beta_20", "Intercept FDP beta_30", "Intercept Greens beta_40", "Intercept Left beta_50",
                      "Gender CDU beta_11", "Gender SPD beta_21", "Gender FDP beta_31", "Gender Greens beta_41", "Gender Left beta_51")
Table2[1,1]     <- 0
Table2[2:5,1]   <- round(summary(m01GER)$coefficients[1:4], digits=2)
Table2[6,1]     <- 0
Table2[7:10,1]  <- round(summary(m01GER)$coefficients[5:8], digits=2)
Table2[2:5,2]   <- round(se.m01GER[1:4], digits=2)
Table2[7:10,2]  <- round(se.m01GER[5:8], digits=2)
Table2[1,3]     <- 1
Table2[2:5,3]   <- round(exp(summary(m01GER)$coefficients[1:4]), digits=2) 
Table2[6,3]     <- 1
Table2[7:10,3]  <- round(exp(summary(m01GER)$coefficients[5:8]), digits=2) 
Table2[1,4]     <- 0
Table2[2:5,4]   <- round(summary(m02GER)$coefficients[1:4], digits=2)
Table2[1,4]     <- 0
Table2[7:10,4]  <- round(summary(m02GER)$coefficients[5:8], digits=2)
Table2[2:5,5]   <- round(se.m02GER[1:4], digits=2)
Table2[7:10,5]  <- round(se.m02GER[5:8], digits=2)
Table2[1,6]     <- 1
Table2[2:5,6]   <- round(exp(summary(m02GER)$coefficients[1:4]), digits=2) 
Table2[6,6]     <- 1
Table2[7:10,6]  <- round(exp(summary(m02GER)$coefficients[5:8]), digits=2) 

Table2 
write.table(Table2, "Table2.txt")



#===============================================================================
# Table 3: Gender based on Effect Coding
#===============================================================================

### Model estimations

# (1 female, -1 male)
m03GER <- mlogit(chosen ~ 0 | genderec | 0, data=ElectionGER1998, shape="long", alt.var="party", reflevel = "CDU")
summary(m03GER)

# (1 male, -1 female)
m04GER <- mlogit(chosen ~ 0 | gender2ec | 0, data=ElectionGER1998, shape="long", alt.var="party", reflevel = "CDU")
summary(m04GER)

# extract s.e.:
se.m03GER <- round(sqrt(diag(solve(-m03GER$hessian))), digits=2)
se.m04GER <- round(sqrt(diag(solve(-m04GER$hessian))), digits=2)

### Build table
Table3 <- matrix(NA, 10, ncol = 6)
colnames(Table3) <- c("beta", "s.e.","e(beta)", "beta", "s.e.", "e(beta)")
rownames(Table3) <- c("Intercept CDU beta_10", "Intercept SPD beta_20", "Intercept FDP beta_30", "Intercept Greens beta_40", "Intercept Left beta_50",
                     "Gender CDU beta_11", "Gender SPD beta_21", "Gender FDP beta_31", "Gender Greens beta_41", "Gender Left beta_51")
Table3[1,1]     <- 0
Table3[2:5,1]   <- round(summary(m03GER)$coefficients[1:4], digits=2)
Table3[6,1]     <- 0
Table3[7:10,1]  <- round(summary(m03GER)$coefficients[5:8], digits=2)
Table3[2:5,2]   <- round(se.m03GER[1:4], digits=2)
Table3[7:10,2]  <- round(se.m03GER[5:8], digits=2)
Table3[1,3]     <- 1
Table3[2:5,3]   <- round(exp(summary(m03GER)$coefficients[1:4]), digits=2) 
Table3[6,3]     <- 1
Table3[7:10,3]  <- round(exp(summary(m03GER)$coefficients[5:8]), digits=2) 
Table3[1,4]     <- 0
Table3[2:5,4]   <- round(summary(m04GER)$coefficients[1:4], digits=2)
Table3[1,4]     <- 0
Table3[7:10,4]  <- round(summary(m04GER)$coefficients[5:8], digits=2)
Table3[2:5,5]   <- round(se.m04GER[1:4], digits=2)
Table3[7:10,5]  <- round(se.m04GER[5:8], digits=2)
Table3[1,6]     <- 1
Table3[2:5,6]   <- round(exp(summary(m04GER)$coefficients[1:4]), digits=2) 
Table3[6,6]     <- 1
Table3[7:10,6]  <- round(exp(Table3[7:10,4]), digits=2) 

Table3 
write.table(Table3, "Table3.txt")


#====================================================================
# Table 4: Empirical Quantities in the Spatial Valence Approach
#====================================================================

### Model estimations

# (0-1 Coding)

#----------------------------------------------------------------------------------------------------
# Model 1: all covariates (reported in Supplementary Materials B.2.1, Table A2)
#----------------------------------------------------------------------------------------------------
m1GER01 <- mlogit(chosen ~ imm + eu + ne + lr | union + work + relig + age2 + gender + west| 0, 
                  data=ElectionGER1998, shape="long", alt.var="party", reflevel = "CDU")
summary(m1GER01)

#-----------------------------------------------------------------------------------------------------
# Model 2: all covariates, gender reversed (reported in Supplementary Materials B.2.1, Table A3)
#-----------------------------------------------------------------------------------------------------
m2GER01 <- mlogit(chosen ~ imm + eu + ne + lr | union + work + relig + age2 + gender2 + west| 0, 
                  data=ElectionGER1998, shape="long", alt.var="party", reflevel = "CDU")
summary(m2GER01)

#------------------------------------------------------------------------------------------------------
# Model 3: covariate region omitted (reported in Supplementary Materials B.2.1, Table A4)
#------------------------------------------------------------------------------------------------------
m3GER01 <- mlogit(chosen ~ imm + eu + ne + lr | union + work + relig + age2 + gender | 0, 
                  data=ElectionGER1998, shape="long", alt.var="party", reflevel = "CDU")
summary(m3GER01)


# Effect Coding

#--------------------------------------------------------------------------------------------------------
# Model 1: all covariates (reported in Supplementary Materials B.2.2, Table A5)
#--------------------------------------------------------------------------------------------------------
m1GERec <- mlogit(chosen ~ imm + eu + ne + lr | unionec + workec + religec + age2 + genderec + westec| 0, 
                  data=ElectionGER1998, shape="long", alt.var="party", reflevel = "CDU")
summary(m1GERec)

#---------------------------------------------------------------------------------------------------------
# Model 2: all covariates, gender reversed (reported in Supplementary Materials B.2.2, Table A6)
#---------------------------------------------------------------------------------------------------------
m2GERec <- mlogit(chosen ~ imm + eu + ne + lr | unionec + workec + religec + age2 + gender2ec + westec| 0, 
                  data=ElectionGER1998, shape="long", alt.var="party", reflevel = "CDU")
summary(m2GERec)

#---------------------------------------------------------------------------------------------------------
# Model 3: covariate region omitted (reported in Supplementary Materials B.2.2, Table A7)
#---------------------------------------------------------------------------------------------------------
m3GERec <- mlogit(chosen ~ imm + eu + ne + lr | unionec + workec + religec + age2 + genderec | 0, 
                  data=ElectionGER1998, shape="long", alt.var="party", reflevel = "CDU")
summary(m3GERec)



### Ranking

# (0-1) Coding

# m1: Model 1 
m1GER01_intercepts <- c(0, round(summary(m1GER01)$coefficients[1], digits=2), 
                        round(summary(m1GER01)$coefficients[2], digits=2),
                        round(summary(m1GER01)$coefficients[3], digits=2), 
                        round(summary(m1GER01)$coefficients[4], digits=2))
m1GER01_intercepts
rankm1GER01 <- rev(sort(m1GER01_intercepts))
rankm1GER01

# m2: Model 2 
m2GER01_intercepts <- c(0, round(summary(m2GER01)$coefficients[1], digits=2), 
                        round(summary(m2GER01)$coefficients[2], digits=2),
                        round(summary(m2GER01)$coefficients[3], digits=2), 
                        round(summary(m2GER01)$coefficients[4], digits=2))
m2GER01_intercepts
rankm2GER01 <- rev(sort(m2GER01_intercepts))
rankm2GER01

# m3: Model 3 
m3GER01_intercepts <- c(0, round(summary(m3GER01)$coefficients[1], digits=2), 
                        round(summary(m3GER01)$coefficients[2], digits=2),
                        round(summary(m3GER01)$coefficients[3], digits=2), 
                        round(summary(m3GER01)$coefficients[4], digits=2))
m3GER01_intercepts
rankm3GER01 <- rev(sort(m3GER01_intercepts))
rankm3GER01


# Effect Coding

# m1: Model 1 
m1GERec_intercepts <- c(0, round(summary(m1GERec)$coefficients[1], digits=2), 
                        round(summary(m1GERec)$coefficients[2], digits=2),
                        round(summary(m1GERec)$coefficients[3], digits=2), 
                        round(summary(m1GERec)$coefficients[4], digits=2))
m1GERec_intercepts
rankm1GERec <- rev(sort(m1GERec_intercepts))
rankm1GERec

# m2: Model 2 
m2GERec_intercepts <- c(0, round(summary(m2GERec)$coefficients[1], digits=2), 
                        round(summary(m2GERec)$coefficients[2], digits=2),
                        round(summary(m2GERec)$coefficients[3], digits=2), 
                        round(summary(m2GERec)$coefficients[4], digits=2))
m2GERec_intercepts
rankm2GERec <- rev(sort(m2GERec_intercepts))
rankm2GERec

# m3: Model 3 
m3GERec_intercepts <- c(0, round(summary(m3GERec)$coefficients[1], digits=2), 
                        round(summary(m3GERec)$coefficients[2], digits=2),
                        round(summary(m3GERec)$coefficients[3], digits=2), 
                        round(summary(m3GERec)$coefficients[4], digits=2))
m3GERec_intercepts
rankm3GERec <- rev(sort(m3GERec_intercepts))
rankm3GERec


### Build table
Table4 <- matrix(NA, 15, ncol = 10)
colnames(Table4) <- c("(0-1) Coding","", "", "", "", "Effect Coding", "", "", "", "")
rownames(Table4) <- c("Model 1: all covariates", "Ranking", "", "λav (1)", "Λ", 
                      "Model 2: all covariates, gender reversed", "Ranking", "", "λav (1)", "Λ", 
                      "Model 3: covariate region omitted", "Ranking", "", "λav (1)", "Λ")

Table4[2,1:5]     <- c("beta_10", "beta_20", "beta_50", "beta_30", "beta_40")
Table4[3,1:5]     <- rankm1GER01
Table4[4,1]       <- round(1/4*(rankm1GER01[1] + rankm1GER01[2] + rankm1GER01[3] + rankm1GER01[4]), digits=2)
Table4[5,1]       <- round((1/4*(rankm1GER01[1] + rankm1GER01[2] + rankm1GER01[3] + rankm1GER01[4])) - rankm1GER01[5], digits=2) 
Table4[7,1:5]     <- c("beta_10", "beta_20", "beta_50", "beta_40", "beta_30")
Table4[8,1:5]     <- rankm2GER01
Table4[9,1]       <- round(1/4*(rankm2GER01[1] + rankm2GER01[2] + rankm2GER01[3] + rankm2GER01[4]), digits=2)
Table4[10,1]      <- round((1/4*(rankm2GER01[1] + rankm2GER01[2] + rankm2GER01[3] + rankm2GER01[4])) - rankm2GER01[5] , digits=2)
Table4[12,1:5]    <- c("beta_20", "beta_10", "beta_30", "beta_50", "beta_40")
Table4[13,1:5]    <- rankm3GER01
Table4[14,1]      <- round(1/4*(rankm3GER01[1] + rankm3GER01[2] + rankm3GER01[3] + rankm3GER01[4]), digits=2)
Table4[15,1]      <- round((1/4*(rankm3GER01[1] + rankm3GER01[2] + rankm3GER01[3] + rankm3GER01[4])) - rankm3GER01[5] , digits=2)
Table4[2,6:10]    <- c("beta_20", "beta_10", "beta_50", "beta_40", "beta_30")
Table4[3,6:10]    <- rankm1GERec
Table4[4,6]       <- round(1/4*(rankm1GERec[1] + rankm1GERec[2] + rankm1GERec[3] + rankm1GERec[4]), digits=2)
Table4[5,6]       <- round((1/4*(rankm1GERec[1] + rankm1GERec[2] + rankm1GERec[3] + rankm1GERec[4])) - rankm1GERec[5], digits=2) 
Table4[7,6:10]    <- c("beta_20", "beta_10", "beta_50", "beta_40", "beta_30")
Table4[8,6:10]    <- rankm2GERec
Table4[9,6]       <- round(1/4*(rankm2GERec[1] + rankm2GERec[2] + rankm2GERec[3] + rankm2GERec[4]), digits=2)
Table4[10,6]      <- round((1/4*(rankm2GERec[1] + rankm2GERec[2] + rankm2GERec[3] + rankm2GERec[4])) - rankm2GERec[5] , digits=2)
Table4[12,6:10]   <- c("beta_20", "beta_10", "beta_50", "beta_40", "beta_30")
Table4[13,6:10]   <- rankm3GERec
Table4[14,6]      <- round(1/4*(rankm3GERec[1] + rankm3GERec[2] + rankm3GERec[3] + rankm3GERec[4]), digits=2)
Table4[15,6]      <- round((1/4*(rankm3GERec[1] + rankm3GERec[2] + rankm3GERec[3] + rankm3GERec[4])) - rankm3GERec[5] , digits=2)

Table4
write.table(Table4, "Table4.txt")


#===================================================================================
# Table 5: Vote Choice Model with Valence Qualities as Candidate Character Traits
#===================================================================================

### Model estimations

#-----------------------------------------------------------------------------
# Model 1
#-----------------------------------------------------------------------------
m1US <- mlogit(chosen ~ lr + spend + def + hea | age2 + genderec + blackec + latinoec | 0, 
               data=ElectionUS2016, shape="long", alt.var="candidate", reflevel = "Democrat")
summary(m1US)


#-----------------------------------------------------------------------------
# Model 2 
#-----------------------------------------------------------------------------
m2US <- mlogit(chosen ~ lr + spend + def + hea + image | age2 + genderec + blackec + latinoec | 0, 
               data=ElectionUS2016, shape="long", alt.var="candidate", reflevel = "Democrat")
summary(m2US)


#-----------------------------------------------------------------------------
# Model 3 
#-----------------------------------------------------------------------------
m3US <- mlogit(chosen ~ lr + spend + def + hea | age2 + genderec + blackec + latinoec | image, 
               data=ElectionUS2016, shape="long", alt.var="candidate", reflevel = "Democrat")
summary(m3US)


# extract s.e.:
se.m1US <- round(sqrt(diag(solve(-m1US$hessian))), digits=2)
se.m1US

se.m2US <- round(sqrt(diag(solve(-m2US$hessian))), digits=2)
se.m2US

se.m3US <- round(sqrt(diag(solve(-m3US$hessian))), digits=2)
se.m3US

### Build table 
Table5<-matrix(NA, 13, ncol = 6)
colnames(Table5) <- c("coef.", "s.e.", "coef.", "s.e.","coef.", "s.e.")
rownames(Table5) <- c("Republican Intercept", "Republican Age", "Republican Female", "Republican Black", "Republican Latino", 
                      "Proximity on Lib-Cons", "Proximity on Spending", "Proximity on Defense", "Proximity on Health Care",
                      "Candidate Character Traits", "Candidate Character Traits: Republican", "Candidate Character Traits: Democrat", 
                      "Log-Lik.")

Table5[1,1]     <- round(summary(m1US)$coefficients[1], digits=2)
Table5[2:5,1]   <- round(summary(m1US)$coefficients[6:9], digits=2)
Table5[6:9,1]   <- round(summary(m1US)$coefficients[2:5], digits=2)
Table5[1,2]     <- round(se.m1US[1], digits=2)
Table5[2:5,2]   <- round(se.m1US[6:9], digits=2)
Table5[6:9,2]   <- round(se.m1US[2:5], digits=2)
Table5[13,1]    <- round(summary(m1US)$logLik, digits=2)
Table5[1,3]     <- round(summary(m2US)$coefficients[1], digits=2)
Table5[2:5,3]   <- round(summary(m2US)$coefficients[7:10], digits=2)
Table5[6:9,3]   <- round(summary(m2US)$coefficients[2:5], digits=2)
Table5[10,3]    <- round(summary(m2US)$coefficients[6], digits=2)
Table5[1,4]     <- round(se.m2US[1], digits=2)
Table5[2:5,4]   <- round(se.m2US[7:10], digits=2)
Table5[6:9,4]   <- round(se.m2US[2:5], digits=2)
Table5[10,4]    <- round(se.m2US[6], digits=2)
Table5[13,3]    <- round(summary(m2US)$logLik, digits=2)
Table5[1,5]     <- round(summary(m3US)$coefficients[1], digits=2)
Table5[2:5,5]   <- round(summary(m3US)$coefficients[6:9], digits=2)
Table5[6:9,5]   <- round(summary(m3US)$coefficients[2:5], digits=2)
Table5[11:12,5] <- round(summary(m3US)$coefficients[10:11], digits=2)
Table5[1,6]     <- round(se.m3US[1], digits=2)
Table5[2:5,6]   <- round(se.m3US[6:9], digits=2)
Table5[6:9,6]   <- round(se.m3US[2:5], digits=2)
Table5[11:12,6] <- round(se.m3US[10:11], digits=2)
Table5[13,5]    <- round(summary(m3US)$logLik, digits=2)

Table5 
write.table(Table5, "Table5.txt")


#=============================================================================
# Table 6: Vote Choice Model with Valence Qualities as Party Leader Images
#=============================================================================


# (a) Valence as Chooser Attributes x_i^(j) with different Reference Parties

### Model estimations 

#-------------------------------------------------------------------------------------
# Lab reference alternative (reported in Supplementary Materials D.2.1, Table A8)
#-------------------------------------------------------------------------------------
m1UK_LAB <- mlogit(chosen ~ taxes + crime | unionec + workec + age2 + genderec + incomeh + ownec + brown + cameron + clegg | 0, 
                   data=ElectionUK2010, shape="long", alt.var="party", reflevel = "Lab")
summary(m1UK_LAB)


#--------------------------------------------------------------------------------------
# CONS reference alternative (reported in Supplementary Materials D.2.1, Table A9)
#--------------------------------------------------------------------------------------
m1UK_CONS <- mlogit(chosen ~ taxes + crime | unionec + workec + age2 + genderec + incomeh + ownec + brown + cameron + clegg | 0, 
                    data=ElectionUK2010, shape="long", alt.var="party", reflevel = "Cons")
summary(m1UK_CONS)

#---------------------------------------------------------------------------------------
# LD reference alternative (reported in Supplementary Materials D.2.1, Table A10)
#---------------------------------------------------------------------------------------
m1UK_LD <- mlogit(chosen ~ taxes + crime | unionec + workec + age2 + genderec + incomeh + ownec + brown + cameron + clegg | 0, 
                  data=ElectionUK2010, shape="long", alt.var="party", reflevel = "LD")
summary(m1UK_LD)

# extract s.e.:
se.m1UK_LAB <- round(sqrt(diag(solve(-m1UK_LAB$hessian))), digits=2)
se.m1UK_LAB

se.m1UK_CONS <- round(sqrt(diag(solve(-m1UK_CONS$hessian))), digits=2)
se.m1UK_CONS

se.m1UK_LD <- round(sqrt(diag(solve(-m1UK_LD$hessian))), digits=2)
se.m1UK_LD 


### Build Table 6a
Table6a<-matrix(NA, 12, ncol = 6)
colnames(Table6a) <- c("beta", "s.e.", "beta", "s.e.", "beta", "s.e.")
rownames(Table6a) <- c("Lab Leader Image x_i^(1)",  "beta_1^(1)", "beta_2^(1)", "beta_3^(1)", 
                       "Cons Leader Image x_i^(2)", "beta_1^(2)", "beta_2^(2)", "beta_3^(2)", 
                       "LD Leader Image x_i^(3)",   "beta_1^(3)", "beta_2^(3)", "beta_3^(3)")

Table6a[2,1]     <- 0
Table6a[3:4,1]   <- round(summary(m1UK_LAB)$coefficients[17:18], digits=2)
Table6a[3:4,2]   <- round(se.m1UK_LAB[17:18], digits=2)
Table6a[6,1]     <- 0
Table6a[7:8,1]   <- round(summary(m1UK_LAB)$coefficients[19:20], digits=2)
Table6a[7:8,2]   <- round(se.m1UK_LAB[19:20], digits=2)
Table6a[10,1]    <- 0
Table6a[11:12,1] <- round(summary(m1UK_LAB)$coefficients[21:22], digits=2)
Table6a[11:12,2] <- round(se.m1UK_LAB[21:22], digits=2)
Table6a[2,3]     <- round(summary(m1UK_CONS)$coefficients[17], digits=2)
Table6a[3,3]     <- 0
Table6a[4,3]     <- round(summary(m1UK_CONS)$coefficients[18], digits=2)
Table6a[2,4]     <- round(se.m1UK_CONS[17], digits=2)
Table6a[4,4]     <- round(se.m1UK_CONS[18], digits=2)
Table6a[6,3]     <- round(summary(m1UK_CONS)$coefficients[19], digits=2)
Table6a[7,3]     <- 0
Table6a[8,3]     <- round(summary(m1UK_CONS)$coefficients[20], digits=2)
Table6a[6,4]     <- round(se.m1UK_CONS[19], digits=2)
Table6a[8,4]     <- round(se.m1UK_CONS[20], digits=2)
Table6a[10,3]    <- round(summary(m1UK_CONS)$coefficients[21], digits=2)
Table6a[11,3]    <- 0
Table6a[12,3]    <- round(summary(m1UK_CONS)$coefficients[22], digits=2)
Table6a[10,4]    <- round(se.m1UK_CONS[21], digits=2)
Table6a[12,4]    <- round(se.m1UK_CONS[22], digits=2)
Table6a[2:3,5]   <- round(summary(m1UK_LD)$coefficients[17:18], digits=2)
Table6a[4,5]     <- 0
Table6a[2:3,6]   <- round(se.m1UK_LD[17:18], digits=2)
Table6a[6:7,5]   <- round(summary(m1UK_LD)$coefficients[19:20], digits=2)
Table6a[8,5]     <- 0
Table6a[6:7,6]   <- round(se.m1UK_LD[19:20], digits=2)
Table6a[10:11,5] <- round(summary(m1UK_LD)$coefficients[21:22], digits=2)
Table6a[12,5]    <- 0
Table6a[10:11,6] <- round(se.m1UK_LD[21:22], digits=2)

Table6a
write.table(Table6a, "Table6a.txt")

# (b) Valence as Choice Attribute z_ij

### Model estimation (reported in Supplementary Materials D.2.2, Table A11)
m2UK_LAB <- mlogit(chosen ~ taxes + crime  | unionec + workec + age2 + genderec + incomeh + ownec  | can, 
                   data=ElectionUK2010, shape="long", alt.var="party", reflevel = "Lab")
summary(m2UK_LAB)

# extract s.e.:
se.m2UK_LAB <- round(sqrt(diag(solve(-m2UK_LAB$hessian))), digits=2)
se.m2UK_LAB


### Build Table 6b
Table6b<-matrix(NA, 3, ncol = 2)
colnames(Table6b) <- c("alpha_j", "s.e.")
rownames(Table6b) <- c("Lab Leader Image", "Cons Leader Image", "LD Leader Image")

Table6b[1:3,1]  <- round(summary(m2UK_LAB)$coefficients[17:19], digits=2)
Table6b[1:3,2]  <- round(se.m2UK_LAB[17:19], digits=2)

Table6b 
write.table(Table6b, "Table6b.txt")



#---------------------------------------------------
#### Estimation Tables Supplementary Materials. 
#---------------------------------------------------


# Supplementary Materials  B.2.1

#====================================================================================================
# Table A2: Vote Choice Model with (0-1) Coding for Categorical Voter Attributes, 
#           Model 1 in Table 4
#====================================================================================================
# m1GER01

# build table
TableA2 <- matrix(NA, 32, ncol = 4)
colnames(TableA2) <-c("coef.", "s.e.", "t-val.", "exp(coef.)")
rownames(TableA2) <-c("Intercept SPD", "Intercept FDP", "Intercept Greens", "Intercept Left", 
                       "Proximity on Immigration", "Proximity on European Integration", "Proximity on Nuclear Energy", "Proximity on Left-Right",
                       "Union Member SPD", "Union Member FDP", "Union Member Greens", "Union Member Left",
                       "Worker SPD", "Worker FDP", "Worker Greens", "Worker Left",
                       "Catholic SPD", "Catholic FDP", "Catholic Greens", "Catholic Left",
                       "Age SPD", "Age FDP", "Age Greens", "Age Left",
                       "Female SPD", "Female FDP", "Female Greens", "Female Left",
                       "West Ger. SPD", "West Ger. FDP", "West Ger. Greens", "West Ger. Left")
TableA2[,1] <- round(summary(m1GER01)$coefficients[1:32], digits=2)
TableA2[,2] <- round(sqrt(diag(solve(-m1GER01$hessian))), digits=2)
TableA2[,3] <- round(summary(m1GER01)$coefficients[1:32]/sqrt(diag(solve(-m1GER01$hessian))), digits=2)
TableA2[,4] <- round(exp(summary(m1GER01)$coefficients[1:32]), digits=2)

TableA2 
write.table(TableA2, "TableA2.txt")

#====================================================================================================
# Table A3: Vote Choice Model with (0-1) Coding for Categorical Voter Attributes (Gender reversed), 
#           Model 2 in Table 4
#====================================================================================================
# m2GER01

# build table
TableA3 <- matrix(NA, 32, ncol = 4)
colnames(TableA3) <- c("coef.", "s.e.", "t-val.", "exp(coef.)")
rownames(TableA3) <- c("Intercept SPD", "Intercept FDP", "Intercept Greens", "Intercept Left", 
                        "Proximity on Immigration", "Proximity on European Integration", "Proximity on Nuclear Energy", "Proximity on Left-Right",
                        "Union Member SPD", "Union Member FDP", "Union Member Greens", "Union Member Left",
                        "Worker SPD", "Worker FDP", "Worker Greens", "Worker Left",
                        "Catholic SPD", "Catholic FDP", "Catholic Greens", "Catholic Left",
                        "Age SPD", "Age FDP", "Age Greens", "Age Left",
                        "Male SPD", "Male FDP", "Male Greens", "Male Left",
                        "West Ger. SPD", "West Ger. FDP", "West Ger. Greens", "West Ger. Left")
TableA3[,1] <- round(summary(m2GER01)$coefficients[1:32], digits=2)
TableA3[,2] <- round(sqrt(diag(solve(-m2GER01$hessian))), digits=2)
TableA3[,3] <- round(summary(m2GER01)$coefficients[1:32]/sqrt(diag(solve(-m2GER01$hessian))), digits=2)
TableA3[,4] <- round(exp(summary(m2GER01)$coefficients[1:32]), digits=2)
 
TableA3 
write.table(TableA3, "TableA3.txt")

#====================================================================================================
# Table A4: Vote Choice Model with (0-1) Coding for Categorical Voter Attributes (Region omitted), 
#           Model 3 in Table 4
#====================================================================================================
# m3GER01

# build table
TableA4 <- matrix(NA, 28, ncol = 4)
colnames(TableA4) <- c("coef.", "s.e.", "t-val.", "exp(coef.)")
rownames(TableA4) <- c("Intercept SPD", "Intercept FDP", "Intercept Greens", "Intercept Left", 
                        "Proximity on Immigration", "Proximity on European Integration", "Proximity on Nuclear Energy", "Proximity on Left-Right",
                        "Union Member SPD", "Union Member FDP", "Union Member Greens", "Union Member Left",
                        "Worker SPD", "Worker FDP", "Worker Greens", "Worker Left",
                        "Catholic SPD", "Catholic FDP", "Catholic Greens", "Catholic Left",
                        "Age SPD", "Age FDP", "Age Greens", "Age Left",
                        "Female SPD", "Female FDP", "Female Greens", "Female Left")
TableA4[,1] <- round(summary(m3GER01)$coefficients[1:28], digits=2)
TableA4[,2] <- round(sqrt(diag(solve(-m3GER01$hessian))), digits=2)
TableA4[,3] <- round(summary(m3GER01)$coefficients[1:28]/sqrt(diag(solve(-m3GER01$hessian))), digits=2)
TableA4[,4] <- round(exp(summary(m3GER01)$coefficients[1:28]), digits=2)

TableA4 
write.table(TableA4, "TableA4.txt")


# Supplementary Materials B.2.2

#====================================================================================================
# Table A5: Vote Choice Model with Effect Coding for Categorical Voter Attributes, 
#           Model 1 in Table 4 
#====================================================================================================
# m1GERec

# build table
TableA5 <- matrix(NA, 32, ncol = 4)
colnames(TableA5 ) <- c("coef.", "s.e.", "t-val.", "exp(coef.)")
rownames(TableA5 ) <- c("Intercept SPD", "Intercept FDP", "Intercept Greens", "Intercept Left", 
                         "Proximity on Immigration", "Proximity on European Integration", "Proximity on Nuclear Energy", "Proximity on Left-Right",
                         "Union Member SPD", "Union Member FDP", "Union Member Greens", "Union Member Left",
                         "Worker SPD", "Worker FDP", "Worker Greens", "Worker Left",
                         "Catholic SPD", "Catholic FDP", "Catholic Greens", "Catholic Left",
                         "Age SPD", "Age FDP", "Age Greens", "Age Left",
                         "Female SPD", "Female FDP", "Female Greens", "Female Left",
                         "West Ger. SPD", "West Ger. FDP", "West Ger. Greens", "West Ger. Left")
TableA5 [,1] <- round(summary(m1GERec)$coefficients[1:32], digits=2)
TableA5 [,2] <- round(sqrt(diag(solve(-m1GERec$hessian))), digits=2)
TableA5 [,3] <- round(summary(m1GERec)$coefficients[1:32]/sqrt(diag(solve(-m1GERec$hessian))), digits=2)
TableA5 [,4] <- round(exp(summary(m1GERec)$coefficients[1:32]), digits=2)

TableA5 
write.table(TableA5, "TableA5.txt")

#====================================================================================================
# Table A6: Vote Choice Model with Effect Coding for Categorical Voter Attributes (Gender reversed), 
#           Model 2 in Table 4 
#====================================================================================================
# m2GERec

# build table
TableA6 <- matrix(NA, 32, ncol = 4)
colnames(TableA6) <- c("coef.", "s.e.", "t-val.", "exp(coef.)")
rownames(TableA6) <- c("Intercept SPD", "Intercept FDP", "Intercept Greens", "Intercept Left", 
                       "Proximity on Immigration", "Proximity on European Integration", "Proximity on Nuclear Energy", "Proximity on Left-Right",
                        "Union Member SPD", "Union Member FDP", "Union Member Greens", "Union Member Left",
                        "Worker SPD", "Worker FDP", "Worker Greens", "Worker Left",
                        "Catholic SPD", "Catholic FDP", "Catholic Greens", "Catholic Left",
                        "Age SPD", "Age FDP", "Age Greens", "Age Left",
                        "Male SPD", "Male FDP", "Male Greens", "Male Left",
                        "West Ger. SPD", "West Ger. FDP", "West Ger. Greens", "West Ger. Left")
TableA6[,1] <- round(summary(m2GERec)$coefficients[1:32], digits=2)
TableA6[,2] <- round(sqrt(diag(solve(-m2GERec$hessian))), digits=2)
TableA6[,3] <- round(summary(m2GERec)$coefficients[1:32]/sqrt(diag(solve(-m2GERec$hessian))), digits=2)
TableA6[,4] <- round(exp(summary(m2GERec)$coefficients[1:32]), digits=2)

TableA6 
write.table(TableA6, "TableA6.txt")

#====================================================================================================
# Table A7: Vote Choice Model with Effect Coding for Categorical Voter Attributes (Region omitted), 
#           Model 3 in Table 4 
#====================================================================================================
# m3GERec

# build table
TableA7<-matrix(NA, 28, ncol = 4)
colnames(TableA7) <- c("coef.", "s.e.", "t-val.", "exp(coef.)")
rownames(TableA7) <- c("Intercept SPD", "Intercept FDP", "Intercept Greens", "Intercept Left", 
                       "Proximity on Immigration", "Proximity on European Integration", "Proximity on Nuclear Energy", "Proximity on Left-Right",
                       "Union Member SPD", "Union Member FDP", "Union Member Greens", "Union Member Left",
                       "Worker SPD", "Worker FDP", "Worker Greens", "Worker Left",
                       "Catholic SPD", "Catholic FDP", "Catholic Greens", "Catholic Left",
                       "Age SPD", "Age FDP", "Age Greens", "Age Left",
                       "Female SPD", "Female FDP", "Female Greens", "Female Left")
TableA7[,1] <- round(summary(m3GERec)$coefficients[1:28], digits=2)
TableA7[,2] <- round(sqrt(diag(solve(-m3GERec$hessian))), digits=2)
TableA7[,3] <- round(summary(m3GERec)$coefficients[1:28]/sqrt(diag(solve(-m3GERec$hessian))), digits=2)
TableA7[,4] <- round(exp(summary(m3GERec)$coefficients[1:28]), digits=2)

TableA7 
write.table(TableA7, "TableA7.txt")


# Supplementary Materials D.2.1

#====================================================================================================
# Table A8: Vote Choice Model with Party Leader Images as Chooser Attribute (Labour Ref.) 
#====================================================================================================
# m1UK_LAB

# build table
TableA8 <- matrix(NA, 22, ncol = 4)
colnames(TableA8) <- c("beta", "s.e.", "t-val.", "e(beta)")
rownames(TableA8) <- c("Intercept Cons", "Intercept LD", "Proximity on Crime", "Proximity on Taxes",
                       "Union Member Cons", "Union Member LD", "Worker Cons", "Worker LD", 
                        "Age Cons", "Age LD", "Female Cons", "Female LD", 
                        "Income Cons", "Income LD", "Homeowner Cons", "Homeowner LD", 
                        "Lab Leader Image: Cons", "Lab Leader Image: LD",
                        "Cons Leader Image: Cons", "Cons Leader Image: LD",
                        "LD Leader Image: Cons", "LD Leader Image: LD")
TableA8[,1] <- round(summary(m1UK_LAB)$coefficients[1:22], digits=2)
TableA8[,2] <- round(sqrt(diag(solve(-m1UK_LAB$hessian))), digits=2)
TableA8[,3] <- round(summary(m1UK_LAB)$coefficients[1:22]/sqrt(diag(solve(-m1UK_LAB$hessian))), digits=2)
TableA8[,4] <- round(exp(summary(m1UK_LAB)$coefficients[1:22]), digits=2)

TableA8 
write.table(TableA8, "TableA8.txt")

#====================================================================================================
# Table A9: Vote Choice Model with Party Leader Images as Chooser Attribute (Conservatives Ref.) 
#====================================================================================================
# m1UK_CONS

# build table
TableA9 <- matrix(NA, 22, ncol = 4)
colnames(TableA9) <- c("beta", "s.e.", "t-val.", "e(beta)")
rownames(TableA9) <- c("Intercept Lab", "Intercept LD", "Proximity on Crime", "Proximity on Taxes",
                        "Union Member Lab", "Union Member LD", "Worker Lab", "Worker LD", 
                        "Age Lab", "Age LD", "Female Lab", "Female LD", 
                        "Income Lab", "Income LD", "Homeowner Lab", "Homeowner LD", 
                        "Lab Leader Image: Lab", "Lab Leader Image: LD",
                        "Cons Leader Image: Lab", "Cons Leader Image: LD",
                        "LD Leader Image: Lab", "LD Leader Image: LD")
TableA9[,1] <- round(summary(m1UK_CONS)$coefficients[1:22], digits=2)
TableA9[,2] <- round(sqrt(diag(solve(-m1UK_CONS$hessian))), digits=2)
TableA9[,3] <- round(summary(m1UK_CONS)$coefficients[1:22]/sqrt(diag(solve(-m1UK_CONS$hessian))), digits=2)
TableA9[,4] <- round(exp(summary(m1UK_CONS)$coefficients[1:22]), digits=2)

TableA9 
write.table(TableA9, "TableA9.txt")

#====================================================================================================
# Table A10: Vote Choice Model with Party Leader Images as Chooser Attribute (Liberal Democrats Ref.)
#====================================================================================================
# m1UK_LD

# build table
TableA10 <- matrix(NA, 22, ncol = 4)
colnames(TableA10 ) <- c("beta", "s.e.", "t-val.", "e(beta)")
rownames(TableA10 ) <- c("Intercept Lab", "Intercept Cons",  "Proximity on Crime", "Proximity on Taxes",
                         "Union Member Lab", "Union Member Cons", "Worker Lab", "Worker Cons", 
                         "Age Lab", "Age Cons", "Female Lab", "Female Cons", 
                         "Income Lab", "Income Cons", "Homeowner Lab", "Homeowner Cons", 
                         "Lab Leader Image: Lab", "Lab Leader Image: Cons",
                         "Cons Leader Image: Lab", "Cons Leader Image: Cons",
                         "LD LeaderImage: Lab", "LD Leader Image: Cons")
TableA10 [,1] <- round(summary(m1UK_LD)$coefficients[1:22], digits=2)
TableA10 [,2] <- round(sqrt(diag(solve(-m1UK_LD$hessian))), digits=2)
TableA10 [,3] <- round(summary(m1UK_LD)$coefficients[1:22]/sqrt(diag(solve(-m1UK_LD$hessian))), digits=2)
TableA10 [,4] <- round(exp(summary(m1UK_LD)$coefficients[1:22]), digits=2)

TableA10 
write.table(TableA10, "TableA10.txt")


# Supplementary Materials D.2.2                                                                     
 
#====================================================================================================
# Table A11: Vote Choice Model with Party Leader Images as Choice Attribute (Labour Ref.) 
#====================================================================================================
# m2UK_LAB

# build table
TableA11 <- matrix(NA, 19, ncol = 4)
colnames(TableA11) <- c("coef", "s.e.", "t-val.", "e(coef)")
rownames(TableA11) <- c("Intercept Cons", "Intercept LD", "Proximity on Crime", "Proximity on Taxes", 
                        "Union Member Cons", "Union Member LD", "Worker Cons", "Worker LD", 
                        "Age Cons", "Age LD", "Female Cons", "Female LD", 
                        "Income Cons", "Income LD", "Homeowner Cons", "Homeowner LD",
                        "Lab Leader Image", "Cons Leader Image", "LD Leader Image")
TableA11[,1] <- round(summary(m2UK_LAB)$coefficients[1:19], digits=2)
TableA11[,2] <- round(sqrt(diag(solve(-m2UK_LAB$hessian))), digits=2)
TableA11[,3] <- round(summary(m2UK_LAB)$coefficients[1:19]/sqrt(diag(solve(-m2UK_LAB$hessian))), digits=2)
TableA11[,4] <- round(exp(summary(m2UK_LAB)$coefficients[1:19]), digits=2)

TableA11 
write.table(TableA11, "TableA11.txt")
